package com.kefu.call.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.basic.vo.BasicRptResultVo;
import com.kefu.call.model.CallGateway;
import com.kefu.call.service.CallGatewayService;
import com.kefu.call.vo.*;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "网关表")
@RestController
@RequestMapping("call/gateway")
public class CallGatewayController extends AbstractBaseController {
    @Resource
    private CallGatewayService callGatewayService;

    @PostMapping("/list")
    @ApiOperation(value = "查询网关表", notes = "查询网关表")
    public Result<Page<CallGateway>> list(@Validated @RequestBody CallGatewaySearchVo search) {
        Page<CallGateway> page = callGatewayService.searchLambdaPage(search);
        page.getRecords().forEach(item->{
            item.setGwNumber(item.getUsername());
        });
        return ResultGenerator.genSuccessResult(page);
    }

    @PostMapping("overview")
    @ApiOperation(value = "概览统计", notes = "概览统计")
    public Result<BasicRptResultVo> overview(@Validated @RequestBody CallGatewayOverviewSearchVo search) {
        BasicRptResultVo resultVo = callGatewayService.overview(search);
        return ResultGenerator.genSuccessResult(resultVo);
    }

    @PostMapping("inbound")
    @ApiOperation(value = "呼入统计", notes = "呼入统计")
    public Result<BasicRptResultVo> inbound(@Validated @RequestBody CallGatewayInboundSearchVo search) {
        BasicRptResultVo result = callGatewayService.inboundRpt(search);
        return ResultGenerator.genSuccessResult(result);
    }

    @PostMapping("outbound")
    @ApiOperation(value = "呼出统计", notes = "呼出统计")
    public Result<BasicRptResultVo> outbound(@Validated @RequestBody CallGatewayOutboundSearchVo search) {
        BasicRptResultVo result = callGatewayService.outboundRpt(search);
        return ResultGenerator.genSuccessResult(result);
    }
}
